package day2;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

//测试输入流
public class TextInput {
    public static void main(String[] args) throws IOException {
        File f = new File("d://io//target.txt");
        if (f.exists()) {
            FileInputStream fis = new FileInputStream(f);
            //read() 运行一次 读取一个字节    返回ascii
            //65-90:DemoA-Z 97-122:a-z      48-57:0-9
            /*int n = fis.read();
            System.out.println(n);
            n = fis.read();
            System.out.println(n);*/

            //f.length() 可以获取文件的总字节 返回long
            /*for (int i = 0; i < f.length(); i++) {
                int n = fis.read();
                System.out.print(n + " ");
            }*/

            //read(字节数组):将读取的内容存入到数组中 返回长度
            byte[] bs = new byte[1024];
            int len = 0;
            while ((len = fis.read(bs)) != -1) {
                //字节数组 转换为字符串
                System.out.println(new String(bs,0,len));
            }
        } else {
            System.out.println("文件不存在!");
        }
    }
}
